<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include_once ("secure_area.php");

class Payments extends Secure_area {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function __construct(){
		parent::__construct();
		$this->load->model('Admin_payments_model');
	}
	public function index(){
		//switch tasks
		$task = isset($_POST['task']) ? strtolower($_POST['task']) : '' ;
	//print_r($_POST['checkid']);
		switch($task){
			case 'delete':
				$id =  isset($_POST['checkid']) ? $_POST['checkid'] : null;
				if( !empty( $id )){

					$this->delete($id);
				} else {
					$this->message->set('error','Please select from the list to delete record');
				}
				break;

			default:

				break;
		}

		$this->page();

	}

	function page($params=''){
		//pagination
		$this->load->library('pagination');
		$start_row = $this->uri->segment(4);
		$limit = 20;
		if(trim($start_row) == ""){
			$start_row = 0;
		}
		$data['title'] = 'Payment Listing';
		$config['base_url'] = site_url('admin/payments/page');
		$config['total_rows'] =  $this->Admin_payments_model->listPayments();
		$data['main_content'] = 'admin/payments_listing';
		$config['per_page'] = $limit;
		$config['uri_segment'] = 4;
		$config['anchor_class'] = 'class="button pagi" ';
		$this->pagination->initialize($config);
		$data['pagination'] = $this->pagination->create_links();
		$data['total_rows'] = $config['total_rows'];
		$data['limit'] = $limit;
		if((!empty($params)) && ($params['action']=='search') && (!empty($params['keyword']))){echo $params['keyword'];exit;
			$data['payments_qry_limited'] = $this->Admin_payments_model->search($params['keyword']);
			$data['total_rows'] = $data['payments_qry_limited']->num_rows();
		}else{
			$data['payments_qry_limited']=$this->Admin_payments_model->listPayments_limited($start_row, $limit);
		}
		$this->load->view('admin/includes/template', $data);
	}

}
